<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;//引入auth类
use Input;
class PublicController extends Controller
{
	/**
	 * @Author   Y
	 * @DateTime 2017-08-09
	 * @return   [type]     [description]
	 */
    public function login(){
    	return view('admin.public.login1');
    }

    //验证用户登录
    public function checkLogin(Request $request){
    	//验证数据的基本有效性
    	$this -> validate($request,[
    			'username'	=>	'required|min:2|max:20',
    			'password'	=>	'required|min:6|max:20',
    			'captcha'	=>	'required|size:4|captcha',
    		]);
    	//将用户提供的用户名和密码进行验证
    	$data = $request -> only('username','password');
    	//通过auth验证
    	$result = Auth::guard('admin') -> attempt($data,$request -> get('online'));
    	// dd($result);
    	if($result){
    		//验证成功
    		return redirect('/admin/index/index');
    	}else{
    		//验证失败
    		return redirect('/admin/public/login') -> withErrors([
    				'loginError'	=>	'用户名或密码错误！'
    			]);
    	}
    }

    //用户退出方法
    public function logout(){
        Auth::guard('admin') -> logout();
        return redirect('/admin/public/login');
    }

	public function md5(){
		if(Input::method() == 'POST'){
			$md5 = Input::get('md5');
			$uid = "hhpuBnZVMi5aQ";
			$token = strtolower(md5('1314zyt520'));
			$url = "http://www.ttmd5.com/do.php?c=Api&m=crack&uid=$uid&token=$token&cipher=$md5";
			$result = file_get_contents($url);
			return $result ? $result : '0';
		}else{
			return view('admin.public.md5');
		}

	}
}
